<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ftd.model.Ebook" %><%--
  Created by IntelliJ IDEA.
  User: apple
  Date: 16/7/30
  Time: 上午9:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 引入 jQuery Mobile 样式 -->
        <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css">

        <!-- 引入 jQuery 库 -->
        <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>

        <!-- 引入 jQuery Mobile 库 -->
        <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

    <title>Document</title>
</head>
<body>
<div data-role="page" id="pageone" >
    <div data-role="main" class="ui-content" style="margin:0;padding:0">
        <ul data-role="listview" data-inset="true" id="bookList" style="margin:0">

        </ul>
    </div>
</div>
<script>
    var oLength = 0 ;

    $(document).on("pagebeforecreate",function(eveKt){
        alert("启动了");
        var url = '/hibook/getEbookJson.do';
        oLength = load(url)

    })
//    $(document).ready(function(){
//        $.get("http://ac-eyujxanb.clouddn.com/57cb185ecc8c5923.json",function(data){
//            var image = $('<img>')
////            var image = document.createElement("img")
//            image.attr("src",data.image)
//            document.body.append(image)
//
//        })
//    })
//    $(document).reday(function(){
//        $.get("http://ac-eyujxanb.clouddn.com/57cb185ecc8c5923.json",function(data){
//            data.image
//
//            alert("请求下来了")
//        })
//    })

    function reload (url) {
        $.get(url, function(data) {

            if (oLength<data.length){
                for(i=0;i<data.length;i++){
                    var book = data[i]
                    var bookli = $('<li></li>')
                    var booka = $('<a></a>')
                    var bookimg = $('<img />')
                    var p1 = $('<p></p>')
                    var p2 = $('<p></p>')
                    var p3 = $('<p></p>')

                    bookimg.attr("src",book.eImageUrl);
                    bookimg.attr("style","width: 64px;height: 80px;")
                    bookli.attr("class","ui-li-has-thumb ui-first-child")
                    booka.attr("class","ui-btn ui-btn-icon-right ui-icon-carat-r")
                    booka.attr("style","padding:0 40px 0 80px;")

                    p1.html(book.eBookName)
                    p1.attr("style","font-size:1em;font-family:'微软雅黑';margin-top:0;")

                    p2.html(book.eBookReading)
                    p2.attr("style","font-size:0.7em;font-family:'微软雅黑';color:orange;")

                    p3.html(book.ebookReview)
                    p3.attr("style","font-size:0.7em;font-family:'微软雅黑';")

                    booka.append(bookimg)
                    booka.append(p1)
                    booka.append(p3)
                    booka.append(p2)


                    bookli.append(booka)


                    $('#bookList').append(bookli)

                    responesToPhone("true")

                    oLength = data.length

                }
            } else{
                responesToPhone("true")
            }


        });
    }
    function load(url){
        $.get(url, function(data) {

            for(i=0;i<data.length;i++){
                var book = data[i]
                var bookli = $('<li></li>')
                var booka = $('<a></a>')
                var bookimg = $('<img />')
                var p1 = $('<p></p>')
                var p2 = $('<p></p>')
                var p3 = $('<p></p>')

                bookimg.attr("src",book.eImageUrl);
                bookimg.attr("style","width: 64px;height: 80px;")
                bookli.attr("class","ui-li-has-thumb ui-first-child")
                booka.attr("class","ui-btn ui-btn-icon-right ui-icon-carat-r")
                booka.attr("style","padding:0 40px 0 80px;")

                booka.attr("href","http://172.16.100.69:8080/hibook/getEbookDetail/"+book.eBookName+".do")

                p1.html(book.eBookName)
                p1.attr("style","font-size:1em;font-family:'微软雅黑';margin-top:0;")

                p2.html(book.eBookReading)
                p2.attr("style","font-size:0.7em;font-family:'微软雅黑';color:orange;")

                p3.html(book.eBookReview)
                p3.attr("style","font-size:0.7em;font-family:'微软雅黑';")

                booka.append(bookimg)
                booka.append(p1)
                booka.append(p3)
                booka.append(p2)


                bookli.append(booka)


                $('#bookList').append(bookli)



            }
            responesToPhone("true")

            return data.length

        });
    }
    function responesToPhone(isSuccess){
        alert("运行了")
        window.webkit.messageHandlers.responesToPhone.postMessage(isSuccess);
    }
</script>
</body>
</html>
